package  
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.sampler.NewObjectSample;
	/**
	 * ...
	 * @author Victor Cruz e Bringel
	 */
	public class Inimigo extends MovieClip
	{
		public static var AR_inimigos: Array= new Array();
		
		public function Inimigo() 
		{
			Main.instance.MC_tela.addChild(this);
			addEventListener(Event.ADDED_TO_STAGE, init);
			
			this.x = Math.random() * 550;
			this.y = Math.random() * 400;

			AR_inimigos.push(this);
		}
		
		public function init(Evento: Event):void
		{
			
		}
		
		public function update(turrent:Turret):void
		{
			var angleRadian: Number = Math.atan2((turrent.y - this.y), (turrent.x - this.x));
			var angleDegree: Number = angleRadian * 180 / Math.PI;
			
			this.rotation = angleDegree;
			
			this.x += Math.cos(((this.rotation) * Math.PI) / 180) * 5; 
			this.y += Math.sin(((this.rotation) * Math.PI) / 180) * 5; 
			
			for (var j:int = 0; j < AR_inimigos.length; j++)
			{
				if (this.hitTestObject(AR_inimigos[j]))
				{
					this.x -= 0.7 * (AR_inimigos[j].x - this.x) / Math.max(Math.abs(AR_inimigos[j].x - this.x), 0.01);
					this.y -= 0.7 * (AR_inimigos[j].y - this.y) / Math.max(Math.abs(AR_inimigos[j].y - this.y), 0.01);
				}
				
				
			}
		}
		public static function updateinimigos(turrent: Turret):void
		{
			for (var i:int = 0; i < AR_inimigos.length; i++)
			{
				AR_inimigos[i].update(turrent);
			}
		}
		public static function criarInimigos(quantidade:int):void
		{
			for (var i:int = 0; i < quantidade; i++)
			{
				var inimigo: Inimigo = new Inimigo(); 
			}
		}
	}

}